<template>
    <el-dialog title="添加" :before-close="handleClose" :visible.sync="is_add_project_form_show">
        <el-form class="dialog-form" label-width="100px">
            <el-form-item label="项目编号：">
                <el-input v-model="project_id"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="handleClose">取消</el-button>
                <el-button type="primary" @click="onSubmit">确定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
import group from '@/api/group.js'

export default {
    name: 'add-project',
    props: ['is_add_project_form_show', 'id'],
    data() {
        return {
            project_id: undefined
        }
    },
    methods: {
        handleClose() {
            this.project_id = undefined;
            this.$emit('update:is_add_project_form_show', false)
        },
        onSubmit() {
            if (this.project_id) {
                group.addProjectIntoGroup({
                    id: this.id,
                    projectId: this.project_id
                }).then(res => {
                    this.$message({
                        type: 'success',
                        message: '添加成功!'
                    });
                }).catch(err => {
                    this.$message.error(err);
                });
                this.handleClose();
            } else {
                return false;
            }
        }
    }
}
</script>

<style>

</style>
